var cmp1={name:"未设置"};

var comboTypeData = [];
comboTypeData.push({categoryCode:"07", name: "油烟机", type:1});
comboTypeData.push({categoryCode:"08", name: "燃气灶", type:1});
comboTypeData.push({categoryCode:"09", name: "消毒柜", type:1});
comboTypeData.push({categoryCode:"10", name:"热水器", type:1});
comboTypeData.push({categoryCode:"11", name:"微波炉", type:1});
comboTypeData.push({categoryCode:"12", name:"洗碗机", type:1});
comboTypeData.push({categoryCode:"16", name:"电烤箱", type:1});
comboTypeData.push({categoryCode:"17", name:"蒸汽炉", type:1});
comboTypeData.push({categoryCode:"20", name:"集成灶", type:1});
comboTypeData.push({categoryCode:"21", name:"微蒸烤一体机", type:1});

comboTypeData.push({categoryCode:"051", name:"刷牙器",type:2});
comboTypeData.push({categoryCode:"063", name:"冲牙器", type:2});

comboTypeData.push({categoryCode:"04", name:"洗衣机", type:3});
comboTypeData.push({categoryCode:"05", name:"干衣机", type:3});
comboTypeData.push({categoryCode:"02", name:"冰箱", type:3});

comboTypeData.push({categoryCode:"06", name:"空调", type:4});

comboTypeData.push({categoryCode:"15", name:"净水产品", type:5});

var currentComboType = null; //当前品类套餐类型
var categoryMap = new Map();
function initPage() {
    //根据当前模式和月份周切换月与周
    if (isMonthType()) {
        $("#label-week").remove();
    } else {
        $("#label-month").remove();
    }
    initMonthWeek("label-for-month", "label-for-week");
    initgzCategorySelect("categorySelect", function (code) {
        //初始化套餐功能
        // initCombo(code);
        //初始化品类规格
        initModelSpecSelect("categorywrapper", code,cmp1);
        // initModelSpecSelect("SettingModelWrapper,#categorybrandShare", code);
        //品类合并plus
        // if (code == "01"||code == "10"||code == "04") {
        //     $("#merge").show();
        // }else {
        //     $("#merge").hide();
        // }
        //重新加载列
        /*var columns = getColumns();
        $("#datagrid").datagrid({
            columns:[columns],
            data:globalData
        });*/
    }, function () {
        // searchBy(1, 100);
    });
    initCategorySelectnew("categorybox");
    initgzCategorySelect("comboMultipleSelect1");
}

function initCombo(code) {
    comboTypeData.forEach(function (c) {
        if (c.categoryCode == code) {
            currentComboType = c.type;
            return;
        }
    });
    //控制套餐拆分
    $("input[name='categoryCode2']").attr("checked", false);
    //显示拆分按钮
    if (code == "07"
        ||code == "051"
        ||code == "05"
        ||code == "06"
        ||code == "15") {
        $("#btn-split").show();
    }else {
        $("#btn-split").hide();
    }
    if (currentComboType==1) {
        $("#comboType1").combobox("clear");
        showComboInput("combo1");
    }else if(currentComboType==2){
        showComboInput("combo2");
    }else if(currentComboType==3){
        showComboInput("combo3");
    } else if(currentComboType==4){
        showComboInput("combo4");
    }  else if(currentComboType==5){
        showComboInput("combo5");
    }
}

function showComboInput(comboId) {
    $("#comboWrapper").show();
    $("#combo1").hide();
    $("#combo2").hide();
    $("#combo3").hide();
    $("#combo4").hide();
    $("#combo5").hide();
    $("#" + comboId).show();
}

function initComboType1() {
    var comboType1List = new Array();
    comboTypeData.forEach(function (c) {
        if (c.type == 1) {
            comboType1List.push(c);
        }
        categoryMap.set(c.categoryCode, c.name);
    });
    $("#comboType1").combobox({
        "textField":"name",
        "valueField":"categoryCode",
        "panelHeight":150,
        // "prompt": "--请选择--",
        "data":comboType1List,
    });
}

function updateSalesDetail(url, data, refresh, methodtype) {
    var method = methodtype || "POST";
    $.ajax({
        url: config.url + url,
        type: method,
        dataType: "json",
        data: data,
        contentType: "application/json;charset=UTF-8",
        xhrFields: {withCredentials: true},
        beforeSend: function () {
            $.messager.progress({
                title: "请稍等",
                interval: 50,
                text: "数据修改中..."
            });
        },
        complete: function () {
            $.messager.progress("close");
        },
        success: function (data) {
            if (data.code == 515) {
                $.messager.alert("提示", data.msg, "error");
                return;
            }

            if (data && refresh) {
                $.messager.alert("提示", "修改成功", "info");
                searchBy();
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $.messager.progress("close");
        }
    })
}

function updateModelAndFocus(url, id) {
    var reportType = window.parent.workMode.toUpperCase();
    id = id || "";
    $.ajax({
        url: config.url + url,
        type: "POST",
        data: {ids: [id], reportType: reportType},
        traditional: true,
        xhrFields: {withCredentials: true},
        beforeSend: function () {
            $.messager.progress({
                title: "请稍等",
                interval: 50,
                text: "操作进行中..."
            });
        },
        complete: function () {
            $.messager.progress("close");
        },
        success: function (data) {
            if (data) {
                //loadCurrentRecord
                var record = window.currentRecord;
                var newrecord = dataForSimilar[$("#orderId").val() - 1];
                var index2 = $("#datagrid").datagrid("getRowIndex", id);
                if (newrecord) {
                    if(newrecord.code.length>=8){
                        $("#datagrid").datagrid("updateRow", {
                            index: index2,
                            row: {brandCode: newrecord.brandCode, modelCode: newrecord.code}
                        });
                    }else{
                        $("#datagrid").datagrid("updateRow", {
                            index: index2,
                            row: {brandCode: newrecord.brandCode, modelCode: ""}
                        });
                    }

                }
                var tr = $(".table-wrapper .datagrid-view2 table.datagrid-btable").find("tr").eq(index2);
                tr.find("input[name='model']").focus();
                setTimeout(function () {
                    tr.find("input[name='model']")[0].setSelectionRange(-1, -1);
                }, 10);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $.messager.progress("close");
        }
    })
}

function updateSalesDetail2(url, data, methodtype) {
    var method = methodtype || "PATCH";
    $.ajax({
        url: config.url + url,
        type: method,
        data: data,
        traditional: true,
        dataType: 'JSON',
        xhrFields: {withCredentials: true},
        beforeSend: function () {
            $.messager.progress({
                title: "请稍等",
                interval: 50,
                text: "操作进行中..."
            });
        },
        complete: function () {
            $.messager.progress("close");
        },
        success: function (data) {
            // console.log(data.msg);
        },
        error: function () {
            $.messager.progress("close");
            // if (data) {
            //     // var res = JSON.parse(data.responseText);
            //     // $.messager.alert("提示", "操作失败", "error");
            // }
        }
    });
}
function updateSalesDetail3(url, data, methodtype) {
    var method = methodtype || "PATCH";
    $.ajax({
        url: config.url + url,
        type: method,
        data: data,
        traditional: true,
        dataType: 'JSON',
        xhrFields: {withCredentials: true},
        beforeSend: function () {
            $.messager.progress({
                title: "请稍等",
                interval: 50,
                text: "操作进行中..."
            });
        },
        complete: function () {
            $.messager.progress("close");
        },
        success: function (data) {
            if(data && data.code==515){
                console.log(data.msg);
                $.messager.alert("提示", data.msg || "操作失败", "error");
            }
        },
        error: function () {
            $.messager.progress("close");
            // if (data) {
            //     // var res = JSON.parse(data.responseText);
            //     // $.messager.alert("提示", "操作失败", "error");
            // }
        }
    });
}
function updateSalesDetaildd(url, data, methodtype) {
    var method = methodtype || "PATCH";
    $.ajax({
        url: config.url + url,
        type: method,
        data: JSON.stringify(data),
        contentType:"application/json;charset=UTF-8",
        xhrFields: {withCredentials: true},
        beforeSend: function () {
            $.messager.progress({
                title: "请稍等",
                interval: 50,
                text: "数据修改中..."
            });
        },
        complete: function () {
            $.messager.progress("close");
        },
        success: function (data) {
            if (data.code == 200) {
                $.messager.alert("提示", data.msg || "修改成功", "info");
                searchBy();
            } else {
                $.messager.alert("提示", data.msg || "修改失败", "error");
            }
        },
        error: function (data) {
            $.messager.progress("close");
            if (data) {
                var res = JSON.parse(data.responseText);
                $.messager.alert("提示", res.err || "操作失败", "error");
            }
        }
    });
}

var dataForSimilar = [];
// bm true是品牌
function searchByModel(model,ele,bm) {
    var params = {};
    params.brand = bm;

    params.categoryCode =  $("#categorySelect").textbox('getValue');
    if(!params.categoryCode){
        $.messager.alert("提示","请选择品类","erre");
        return;
    }
    params.regex = model;
    // var $this = ele;
    // var id = $this.id;  //点击一条数据没有值
    params.id = window.currentRecord.id;
    var reportType = window.parent.workMode.toUpperCase();
    params.reportType = reportType;
    var formdata = getFormData(document.getElementById("ff"));
    params.year = formdata.year;
    if (isMonthType()) {
        params.month = formdata.month;
    } else {
        params.week = formdata.week;
    }
    dataForSimilar = [];
    $("#similarmodel-list").html("<li class='list-item'><span class='blue'>正在读取数据...</span></li>");
    $.ajax({
        url: config.url + "/sales/detail/searchModel",
        type: "GET",
        data: params,
        dataType: "json",
        xhrFields: {withCredentials: true},
        success: function (data) {
            if (data.code && data.code == 515) {
                $("#similarmodel-list").html("<li class='list-item'><span class='red'>"+data.msg+"</span></li>");
                return
            }
            if (data && data.length > 0) {
                if(bm){
                    dataForSimilar = data;
                    $("#similarmodel-list").html(renderBrandList(data,formdata.year));
                }else{
                    var ysxh = data[0].excluderesult;
                    $("#modelName").textbox("setValue", ysxh);
                    if (data[0].name) {
                        dataForSimilar = data;
                        $("#similarmodel-list").html(renderModelList(data,formdata.year));
                        //添加为当型号只存在一个并且完全匹配时自动填充保存，不需要此功能
                        // if (data.length == 1) {
                        //     var record = window.currentRecord;
                        //     if (record.modelCode == null) {
                        //         var values = data[0].name.replace("-", ".?");
                        //         ysxh = ysxh.replace("-", ".?");
                        //         if (values == ysxh) {
                        //             var newrecord = data[0];
                        //             var index2 = $("#datagrid").datagrid("getRowIndex",record.id);
                        //             if (newrecord) {
                        //                 $("#datagrid").datagrid("updateRow", {
                        //                     index: index2,
                        //                     row: {modelCode: newrecord.code}//这是赋值的会定位看框里把值附上
                        //
                        //                 });
                        //             }
                        //             batchReplace(record.id, data[0].code);
                        //             //光标定位到本行型号列
                        //             var tr = $(".table-wrapper .datagrid-view2 table.datagrid-btable").find("tr").eq(index2);
                        //             // console.log(tr);
                        //             // console.log("第"+(index2+1)+"行,,,,要编码的行为"+record.id+"型号码为"+data[0].code)
                        //             tr.find("input[name=model]").focus();
                        //         }
                        //     }
                        // }
                    } else {
                        dataForSimilar = [];
                        $("#similarmodel-list").html("<li class='list-item'><span class='red'>没有找到记录</span></li>");
                    }
                }
            } else {
                dataForSimilar = [];
                $("#similarmodel-list").html("<li class='list-item'><span class='red'>没有找到记录</span></li>");
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {

        }
    });
}
function searchByModelOne(model,ele) {
    var $this = ele;
    var id = $this.id;
    var params = {};
    params.modelCode = model;
    var formdata = getFormData(document.getElementById("ff"));
    params.year = formdata.year;
    dataForSimilar = [];
    $("#similarmodel-list").html("<li class='list-item'><span class='blue'>正在读取数据...</span></li>");
    $.ajax({
        url: config.url + "/model/searchModel",
        type: "GET",
        data: params,
        dataType: "json",
        xhrFields: {withCredentials: true},
        success: function (data) {
            if (data.code && data.code == 515) {
                $("#similarmodel-list").html("<li class='list-item'><span class='red'>"+data.msg+"</span></li>");
                return
            }
            if (data) {
                dataForSimilar = data;
                if($("#modelName").textbox("getValue") == "--"){
                    $("#modelName").textbox("setValue",data.name);
                }

                var arr1 = new Array();
                arr1.push(data);
                $("#similarmodel-list").html(renderModelList(arr1,formdata.year));
            } else {
                $("#similarmodel-list").html("<li class='list-item'><span class='red'>没有找到记录</span></li>");
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {

        }
    });
}
function renderModelList(list,year) {

    var reportType = window.parent.workMode.toUpperCase();
    var items = [];
    var template = "<li class='list-item'>" +
        "<a class='clearfix'><span class='red'>{{code}}</span><span class='orderId'>{{orderId}}</span></a>" +
        "<a class='blue'>{{name}}</a>" +
        "<a>均价：{{avgPrice}}</a>" +
        "<a>上市价：{{onSellPrice}}</a>" +
        "<a class='blue'>{{cmName}}：{{cmValue}}</a>" +
        "<a class='blue'>别名：{{alias}}</a>" +
        "<a class='blue'>-----------------------</a>" +
        "</li>";
    var cmCode;
    var cmName="第一规格";
    if(cmp1){
        cmCode=cmp1.code;
        cmName=cmp1.name;
    }
    for (var i = 0; i < list.length; i++) {
        var item = list[i];
        var tmp = template.replace("{{code}}", item.code);
        tmp = tmp.replace("{{name}}", item.name);
        tmp = tmp.replace("{{onSellPrice}}", item.onSellPrice);
        tmp = tmp.replace("{{cmName}}", cmName);
        var cc=0;
        if(cmCode){
            item.properties.forEach(function (c) {
                if(c.code==cmCode){
                    tmp = tmp.replace("{{cmValue}}", c.value);
                    cc=1;
                    return;
                }
            })
        }
        if(cc == 0 ){
            tmp = tmp.replace("{{cmValue}}", null);
        }

        var modelAvgPrice;
        if (reportType == "MONTH") {
            if (year == 2018) {
                modelAvgPrice = item.offlineMonthAvgPrice2018 || "--";
                modelAvgPrice = '[2018线下月] ' + modelAvgPrice;
            }else if (year == 2019) {
                modelAvgPrice = item.offlineMonthAvgPrice2019 || "--";
                modelAvgPrice = '[2019线下月] ' + modelAvgPrice;
            }else if(year == 2020) {
                modelAvgPrice = item.offlineMonthAvgPrice2020 || "--";
                modelAvgPrice = '[2020线下月] ' + modelAvgPrice;
            }else  {
                modelAvgPrice = item.offlineMonthAvgPrice || "--";
                modelAvgPrice = '[线下月] ' + modelAvgPrice;
            }
        }else if (reportType == "ONLINE") {
            if (year == 2018) {
                modelAvgPrice = item.onlineAvgPrice2018 || "--";
                modelAvgPrice = '[2018线上周] ' + modelAvgPrice;
            }else if (year == 2019) {
                modelAvgPrice = item.onlineAvgPrice2019 || "--";
                modelAvgPrice = '[2019线上周] ' + modelAvgPrice;
            }else if (year == 2020) {
                modelAvgPrice = item.onlineAvgPrice2020 || "--";
                modelAvgPrice = '[2020线上周] ' + modelAvgPrice;
            }else{
                modelAvgPrice = item.onlineAvgPrice || "--";
                modelAvgPrice = '[线上周] ' + modelAvgPrice;
            }
        }else if(reportType == "ONLINE_M"){
            if (year == 2019) {
                modelAvgPrice = item.onlineMonthAvgPrice2019 || "--";
                modelAvgPrice = '[2019线上月] ' + modelAvgPrice;
            }else if (year == 2020) {
                modelAvgPrice = item.onlineMonthAvgPrice2020 || "--";
                modelAvgPrice = '[2020线上月] ' + modelAvgPrice;
            }else {
                modelAvgPrice = item.onlineMonthAvgPrice || "--";
                modelAvgPrice = '[线上月] ' + modelAvgPrice;
            }
        } else if (reportType == "PDK_W") {
                modelAvgPrice = item.pdkWeekAvgPrice || "--";
                modelAvgPrice = '[拼抖快周] ' + modelAvgPrice;
        }else if(reportType == "PDK_M"){
                modelAvgPrice = item.pdkMonthAvgPrice || "--";
                modelAvgPrice = '[拼抖快月] ' + modelAvgPrice;
        } else {
            if(year == 2018){
                modelAvgPrice = item.offlineAvgPrice2018 || "--";
                modelAvgPrice = '[2018线下周] ' + modelAvgPrice;
            }else if(year == 2019){
                modelAvgPrice = item.offlineAvgPrice2019 || "--";
                modelAvgPrice = '[2019线下周] ' + modelAvgPrice;
            }else if(year == 2020){
                modelAvgPrice = item.offlineAvgPrice2020 || "--";
                modelAvgPrice = '[2020线下周] ' + modelAvgPrice;
            }else {
                modelAvgPrice = item.offlineAvgPrice || "--";
                modelAvgPrice = '[线下周] ' + modelAvgPrice;
            }
        }

        tmp = tmp.replace("{{avgPrice}}", modelAvgPrice);
        tmp = tmp.replace("{{orderId}}", i + 1);
        tmp = tmp.replace("{{alias}}", item.otherNames ? item.otherNames.join("、") : "");
        items.push(tmp);
    }
    return items.join("");
}
function renderBrandList(list,year) {

    var reportType = window.parent.workMode.toUpperCase();
    var items = [];
    var template = "<li class='list-item'>" +
        "<a class='clearfix'><span class='red'>{{code}}</span><span class='orderId'>{{orderId}}</span></a>" +
        "<a class='blue'>{{brandName}}</a>" +
        "<a>英文名：{{name}}</a>" +
        "<a class='blue'>别名：{{alias}}</a>" +
        "<a class='blue'>-----------------------</a>" +
        "</li>";
    for (var i = 0; i < list.length; i++) {
        var item = list[i];
        var tmp = template.replace("{{code}}", item.brandCode);
        tmp = tmp.replace("{{brandName}}", item.brandName);
        tmp = tmp.replace("{{name}}", item.name);

        tmp = tmp.replace("{{orderId}}", i + 1);
        tmp = tmp.replace("{{alias}}",  item.otherNames ? item.otherNames.join("、") : "");
        items.push(tmp);
    }
    return items.join("");
}
var columns_map = {};
columns_map.ck = {field: 'id', checkbox: true};
columns_map.analyzecategory = {field: "categoryName", formatter: categoryResultFormatter, title: "品类", align: "center", width: 50};
columns_map.brandCode = {field: "brandCode", formatter: brandinputFormatter, title: "品牌编码", align: "center", width: 40};
columns_map.seriesCode = {field: "seriesCode", formatter: seriesInputFormatter, title: "3C系列码", align: "center", width: 60,checkbox: false};
columns_map.modelCode = {field: "modelCode", formatter: modelinputFormatter, title: "型号编码", align: "center", width: 40};
columns_map.brandmodel = {field: "brandName", formatter: brandFormatter, title: "品牌|原始品牌", align: "center", width: 80};
columns_map.namemodel = {field: "namemodel", formatter: namemodeFormatter, title: "型号|原始型号", align: "left", width: 180};
columns_map.comboRemark = {field: "comboRemark", formatter: comboRemarkFormatter, title: "套餐备注",  width: 80};
columns_map.amounts = {field: "amounts", formatter: accountsFormatter, title: "原|现销量", align: "center", width: 40};
columns_map.prices = {field: "prices", formatter: pricesFormatter, title: "原|现|均价", align: "center", width: 80};
columns_map.mallName = {field: "mallCode", title: "商场码", align: "center", width: 40};
columns_map.channelName = {field: "channelCode", title: "渠道码", align: "center", width: 25};
columns_map.user = {field: "operateUser", title: "操作人", align: "center", width: 55};

// columns_map.action = {field:"action",formatter:actions,title:"操作",align:"center",width:120};
function categoryResultFormatter(val, row) {
    var categoryMark = "";
    if (row.categoryColumnMark) {
        categoryMark = "<label class='green'>" + row.categoryColumnMark + "</label>";
    }
    var disable = "";
    if (row.entityStatus == "DISABLE") {
        disable = "<label class='red'>[禁用]</label>"
    }
    return val + categoryMark + disable;
}

function brandinputFormatter(val, row) {
    var brand = val || "";
    return "<input id='" + row.id + "' type='text' class='datagrid-text' name='brand' style='width:60px;color:green;' _value='" + brand + "'  value='" + brand + "'/>";
}

function seriesInputFormatter(val, row) {
    let seriesCode = row.seriesTo3cCode || "";
    return "<input id='" + row.id + "' type='text' class='datagrid-text' name='seriesTo3c' style='width:50px;color:green;' _value='" + seriesCode + "'  value='" + seriesCode + "'/>"+row.seriesName;
}

function modelinputFormatter(val, row) {
    var model = val || "";
    return "<input id='" + row.id + "' type='text' class='datagrid-text' name='model' style='width:74px;color:red;' _value='" + model + "'  value='" + model + "'/>";
}

function brandFormatter(val, row) {
    var originalBrand = row.originalBrand || "--";
    return row.brandName + "<label class='red'>|</label>" + originalBrand;
}

function namemodeFormatter(val, row) {
    var modelMark = "";
    if (row.modelColumnMark) {
        modelMark = "<label class='red'>" + row.modelColumnMark + "</label>";
    }
    return modelMark +row.modelName  + "<label class='red' style='font-weight:bolder'>|</label>" + row.originalModel ;
}

function accountsFormatter(val, row) {
    var originalCount = row.originalCount || 0;
    var count = row.count || 0;
    return originalCount + " | " + count;
}

function pricesFormatter(val, row) {
    var originalPrice = row.originalPrice || 0;
    var avgPrice;
    if (window.parent.workMode.toUpperCase() == "MONTH") {
        avgPrice = row.offlineMonthAvgPrice || '-';
    }else if("ONLINE" == window.parent.workMode.toUpperCase()){
        avgPrice = row.onlineAvgPrice || '-';
    }else if("ONLINE_M" == window.parent.workMode.toUpperCase()){
        avgPrice = row.onlineMonthAvgPrice || '-';
    }else if("PDK_W" == window.parent.workMode.toUpperCase()){
        avgPrice = row.pdkWeekAvgPrice || '-';
    }else if("PDK_M" == window.parent.workMode.toUpperCase()){
        avgPrice = row.pdkMonthAvgPrice || '-';
    }else {
        avgPrice = row.avgPrice || '-';
    }
    var price = row.price || 0;

    return originalPrice + " | " +
        "<input id='" + row.id + "' type='text' class='datagrid-text' name='price' style='color:red;' _value='" + price + "' value='" + price + "'/>" +
        " | " + avgPrice;
}

/**
 * 套餐备注
 * @param val
 * @param row
 * @returns {*}
 */
function comboRemarkFormatter(val, row) {
    var modelCode = row.modelCode;
    var categoryColumnMark = row.categoryColumnMark;
    row.originalModel = row.originalModel.replace(/'/g,"’");
    if (row.originalBrand) {
        row.originalBrand = row.originalBrand.replace(/'/g,"’");
    }
    if (row.brandName) {
        row.brandName = row.brandName.replace(/'/g,"’");
    }
    if (row.participle) {
        var a=[];
        row.participle.forEach(function (pe) {
            if(pe){
                pe = pe.replace(/'/g,"’");
                a.push(pe);
            }
        })
        row.participle=a;
    }
    var rowJson = JSON.stringify(row);
    // var originalModel = row.originalModel.replace(/'/g,"’");
    var content = "<a class='l-btn-left l-btn-icon-left' style='width:22px;height: 24px' onclick='copyModel(\""+row.originalModel+"\")'><span class='l-btn-icon icon-copy'></span></a>";
    let queryType = $("#unusualcombobx").combobox("getValue");
    if (row.url && row.url.startsWith("http")) {
        var hrefUrl = row.url;
        //拼抖快商品生成二维码
        if (row.channelCode == '0191') {
            //拼多多
            hrefUrl = "/webapp/util/QRcode.html?content="+row.url;
            var index = row.url.indexOf(".html");
            if (index > 0) {
                var newUrl = row.url.slice(0, index) + '2' + row.url.slice(index);
                hrefUrl += "____" + newUrl;
            }
        }else if(row.channelCode == '0173'||row.channelCode == '0174'){
            //抖音、快手、淘宝
            hrefUrl = "/webapp/util/QRcode.html?content="+row.url;
            if(row.channelCode == '0102'){
                let indexOf = row.url.indexOf("id=");
                if (indexOf > 0) {
                    let skuId = row.url.slice(indexOf);
                    hrefUrl += "____" + "https://detail.m.tmall.com/item.htm?" + skuId;
                    hrefUrl += "____" + "https://new.m.taobao.com/detail.htm?ft=t&" + skuId;
                }
            }
        }
        content += "<a href=\""+hrefUrl+"\" target=\"_Blank\" class='l-btn-left l-btn-icon-left' style='width:22px;height: 24px; margin-left: 6px'><span class='l-btn-icon icon-url'></span></a>";
        if (row.channelCode == "0135" && queryType != "Q20") {
            // content += "<button onclick='adjPrice(" + rowJson + ")' style='height: 25px;width:36px;margin-left: 6px;background:#cde5fd'>调价</button>";
        }
        if (row.channelCode == "0135" || row.channelCode == "0102") {
            content += "<button onclick='showImgDetail(" + rowJson + ")' style='height: 25px;width:36px;margin-left: 6px;background:#cde5fd'>图片</button>";
        }
    }
    if (/套/.test(categoryColumnMark) && !modelCode) {
        val = val || "";
        content += "<button onclick='addModel(" + rowJson + ")' style='height: 25px;width:35px; margin-left:4px;background:#cde5fd'>添加</button>" +
            "<input id='" + row.id + "' type='text' class='datagrid-text' name='comboRemark' style='color:red;width:130px;' _value='" + val + "' value='" + val + "'/>";
    } else if (!modelCode) {
        content += "<button onclick='addModel(" + rowJson + ")' style='height: 25px;width:35px;margin-left:4px;background:#cde5fd'>添加</button>";
    } else {
        if (row.otherNameFlag == 0 && queryType == "Q20" && row.categoryType != 2) {
            content += "<button onclick='addparticiple(" + rowJson + ")' style='height: 25px;width:60px;margin-left:4px;background:#cde5fd'>加别名</button>";
        }
    }
    return content;
}

function copyModel(content) {
    var flag = copyText(content);
    $.messager.show({
        title: '提示',
        msg: flag?"型号复制成功":"型号复制失败",
        timeout: 500,
        showType: 'fade'
    });
}
function wordCopyUrl(row) {

    var flag = copyText(row.url);
    $.messager.show({
        title: '提示',
        msg: flag?"网址复制成功":"网址复制失败",
        timeout: 500,
        showType: 'fade'
    });
}

function addModel(row) {
    //清空当前值
    $('#filling').form('clear');
    imgAnalyzeData = [];
    imgAnalyzeModels = {};
    imgSizeProp = {};
    $("#imgAnalyzeDiv").hide();
    $("#imgAnalyze").attr("disabled", false);
    $("#showImg").attr("disabled", false);
    $("#jdImg").empty();
    $("#jdImg").hide();
    $("#propTable").empty();
    $("#propDetail").hide();
    $("#imgAnalyzeSelect").combobox('clear');   //清除选中值
    $("#imgAnalyzeSelect").combobox('loadData', {});    //清空下拉框内容
    // $("#inputSearch").searchbox('setValue','');
    $(".img_content").remove();
    $("#imgModelConfirm").hide();
    //3c
    if (categoryType == 2) {
        $("#modelNameDiv").hide();
        $("#modelNameNew").textbox("setValue", "1"); //3c产品不用写型号，初始化name用于表单验证
    } else {
        $("#modelNameDiv").show();
    }
    //页面赋值
    $("#categorySelectAdd").combobox("select", row.categoryCode);
    $('#dataId').val(row.id);
    //转换描述信息
    descriptionConvert(row);

    $('#originalModelAdd').textbox('setValue', row.originalModel);
    $('#participle').textbox('setValue', row.participle);

    $.when(addProp(row.categoryCode)).done(function () {
        initFormDataBySkuMark(row.url, row.categoryCode)
    });
    initBrandSelectC("brandSelectAdd", function () {
        initSeries(row.categoryCode, "brandSelectAdd", row.seriesTo3cCode)
    }, null, row.categoryCode,row.brandCode);

    $('#addModelNone').dialog({
        width: "1560px",
        left: '173px'
    }).dialog('open');
    // if(row.channelCode=="0102"||row.channelCode=="0135"){    //天猫渠道自动识别图片
    //     getImgAnalyzeData(row.id);
    // }
}

function descriptionConvert(row){
    if (row.url && row.url != "null") {
        $('#description').tagbox('setValue', row.url);
    } else if (row.channelCode == "0102") {   //天猫
        var name = row.originalModel.replace(/\s+/g, "");
        var url = "https://list.tmall.com/search_product.htm?q=" + name + "&type=p";
        $('#description').tagbox('setValue', url);
    } else if (row.channelCode == "0098" || row.channelCode == "0009") {   //苏宁
        var name = row.originalModel.replace(/\s+/g, "").replace("/", "%252F").replace("-", "%252d");
        var url = "https://search.suning.com/" + name + "/";
        $('#description').tagbox('setValue', url);
    } else if (row.channelCode == "0097" || row.channelCode == "0010") {   //国美
        var name = row.originalModel.replace(/\s+/g, "");
        var url = "https://search.gome.com.cn/search?question=" + name + "&searchType=goods";
        $('#description').tagbox('setValue', url);
    }
}

var imgAnalyzeModels = {};
function getImgAnalyzeData(id) {
    $.ajax({
        url: window.config.url+"/workshop/getImgAnalyzeData/"+id,
        type: "post",
        dataType: "json",
        xhrFields: {withCredentials: true},
        beforeSend: function () {
            $.messager.progress({
                title: "请稍等",
                interval: 50,
                text: "图片识别中..."
            });
        },
        complete: function () {
            $.messager.progress("close");
        },
        success: function (data) {
            $.messager.progress("close");
            if (data.code != 200) {
                $.messager.alert("提示", data.msg, "error");
                return;
            }
            imgAnalyzeModels = {};
            if (data.msg) {
                imgAnalyzeData = data.msg.imgAnalyzeInfos;
                //显示图片，只有在图片初始化完毕才能显示内容
                openImg(data.msg.imgs);
                if(data.msg.tmallimagess){
                    showProp(data.msg.tmallimagess.itemProperties);
                }

                if(data.msg.models&&data.msg.models.length>0){
                    //初始化选择框（这里是识别的型号）
                    var selectContent = []; //识别到的内容
                    selectContent.push({"code":"", "value": ""});
                    for (const imgAnalyzeModel of data.msg.models) {
                        let modelInfo = imgAnalyzeModel["modelInfo"];
                        let name = modelInfo.substring(modelInfo.indexOf("&") + 1);
                        let analyzeInfos = imgAnalyzeModel["analyzeInfo"];
                        for (let i = 0; i < analyzeInfos.length; i++) {
                            let key = modelInfo + ":" + i;      //key格式  型号码 +&+型号名+:+重复次数
                            var select;
                            if (i == 0) {
                                select= {"code":key, "value": name};
                            }else {
                                select= {"code":key, "value": "<span style='color: red'>("+i+")</span>"+name};
                            }
                            imgAnalyzeModels[key] = analyzeInfos[i];
                            selectContent.push(select);
                        }
                    }
                    $("#imgModelConfirm").show();
                    imgAnalyzeSelect(selectContent);
                }
                $("#imgAnalyze").attr("disabled", true);
                $("#showImg").attr("disabled", true);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $.messager.progress("close");
        }
    })

}

function imgModelConfirm() {
    let modelInfo = $("#imgAnalyzeSelect").combobox("getValue");
    if (!modelInfo) {
        $.messager.alert("提示", "请选择型号信息", "error");
        return;
    }
    let modelCode = modelInfo.substring(0,modelInfo.indexOf("&"));
    let id = $("#dataId").val();
    $.ajax({
        url: window.config.url+"/workshop/imgModelConfirm/"+id,
        type: "post",
        dataType: "json",
        data:{modelCode: modelCode},
        xhrFields: {withCredentials: true},
        beforeSend: function () {
            $.messager.progress({
                title: "请稍等",
                interval: 50,
                text: "操作中..."
            });
        },
        complete: function () {
            $.messager.progress("close");
        },
        success: function (data) {
            $.messager.progress("close");
            if (data.code != 200) {
                $.messager.alert("提示", data.msg, "error");
                return;
            }
            $('#addModelNone').dialog('close');
            searchBy();
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $.messager.progress("close");
        }
    })
}
function addparticiple(row) {
    //清空当前值
    $('#formParticiple').form('clear');
    $('#participle').combobox('loadData', {});//清空option选项
    //页面赋值
    $('#originalModelPar').textbox('setValue',row.originalModel);
    $('#originalModelPar').textbox('textbox').attr('readonly',true);
    $('#otherNameDataId').val(row.id);
    $('#modelC').textbox('setValue', row.modelCode);
    $('#modelC').textbox('textbox').attr('readonly',true);
    $('#modelN').textbox('setValue', row.modelName).attr('readonly',true);
    $('#modelN').textbox('textbox').attr('readonly',true);
    var participle = [];
    if (row.participlePlus) {
        if (row.participlePlus[1]) {
            participle = participle.concat(row.participlePlus[1]);
        }
        if (row.participlePlus[2]) {
            participle = participle.concat(row.participlePlus[2]);
        }
    }
    participleSelect("participle",participle);
    $('#addModelParticiple').dialog('open');
    $("#participle").combogrid('textbox').focus();
}

function adjPrice(row) {
    var num= row.url.replace(/[^0-9]/ig,"");
    $.ajax({
        url: window.config.jdUrl+"/jdPrice_detail/"+num,
        type: "post",
        dataType: "json",
        data:{'category': row.originalCategory},
        xhrFields: {withCredentials: true},
        beforeSend: function () {
            $.messager.progress({
                title: "请稍等",
                interval: 50,
                text: "价格查询中..."
            });
        },
        complete: function () {
            $.messager.progress("close");
        },
        success: function (data) {
            if (data.code != 200) {
                $.messager.alert("提示", "查询失败", "error");
                return;
            }
            if (!data.msg.PromotionPrice) {
                $.messager.alert("提示", "获取价格失败", "error");
                return;
            }
            var url = "/sales/detail/price/change/" + data.msg.PromotionPrice;
            updateSalesDetail2(url, {ids: [row.id], reportType: window.parent.workMode.toUpperCase()}, "POST");
            searchBy();
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $.messager.progress("close");
        }
    })
}

function showImgDetail(row){
    $("#jdImg").empty();
    //转换描述信息
    descriptionConvert(row);
    //获取请求地址
    let reqUrl = getReqUrl();
    if(!reqUrl){
        return;
    }
    //如果不是天猫就打开添加型号页面，因为天猫要去跳转
    if (!reqUrl.match("taoTmdemo")) {
        $('#addModelNone').dialog({
            width: "1560px",
            left: '173px'
        }).dialog('open');
    }
    //请求图片
    reqImgUrl(reqUrl);
}

function initFormDataBySkuMark(skuMark, categoryCode) {
    if (!skuMark) {
        return;
    }
    //目前只支持美发系列
    if (categoryCode != "29") {
        return;
    }
    $.ajax({
        url: config.url + "/skuProperties/findBySkuMark",
        type:'post',
        data: {skuMark:skuMark,categoryCode:categoryCode},
        dataType:"json",
        xhrFields:{withCredentials:true},
        success:function (data) {
            if (data.code == 200) {
                var formdata = [];
                let skuProperties = data.msg;
                if (skuProperties.onSellYear) {
                    formdata['onSellYear'] = skuProperties.onSellYear;
                    formdata['onSellWeek'] = skuProperties.onSellWeek;
                    formdata['onSellMonth'] = skuProperties.onSellMonth;
                }
                if(categoryCode == "29"){
                    if (skuProperties.prop1) {
                        formdata["04559"] = skuProperties.prop1.toString(); //产品类型  SELECTED
                    }
                    if (skuProperties.prop2) {
                        formdata["04560"] = skuProperties.prop2.toString(); //负离子   boolean
                    }
                    if (skuProperties.prop3) {
                        formdata["04771"] = skuProperties.prop3.toString(); //纳米水离子 boolean
                    }
                    if (skuProperties.prop4) {
                        formdata["04561"] = skuProperties.prop4.toString(); //手柄可折叠 BOOLEAN
                    }
                    if (skuProperties.prop5) {
                        formdata["04562"] = skuProperties.prop5.toString(); //功率    NUMBER
                    }
                    if (skuProperties.prop6) {
                        formdata["04563"] = skuProperties.prop6.toString(); //造型效果  SELECTED
                    }
                }
                $("#filling").form("load",formdata);
            }
        }
    });
}


function getColumns() {
    var arr = $(".column-list-select").find("input").map(function (index, item) {
        var _key = $(item).attr("id");
        var checked = $(item).prop("checked");
        return {key: _key, value: checked};
    }).filter(function (index, item) {
        return item.value == true;
    });
    var res = [];
    $(arr).each(function (index, item) {
        res.push(columns_map[item.key]);
    });
    //res.push(columns_map.action);
    res.unshift(columns_map.ck);
    return res;
}

function enableAll() {
    var url = "/sales/detail/enable";
    batchUpdate(url, "启用");
}

function batchUpdate(url, message) {
    var selectedRow = $("#datagrid").datagrid("getChecked");
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item, index) {
            return item.id;
        });
        //return false;
        $.messager.confirm("提示", "您确定" + message + "吗?", function (r) {
            if (r) {
                updateSalesDetail(url, JSON.stringify(ids), true);
            }
        });
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}

function disableAll() {
    var url = "/sales/detail/disable";
    batchUpdate(url, "禁用");
}

/**
 * 本期禁用（特殊禁用）
 */
function disablePeriod() {
    var url = "/sales/detail/disablePeriod";
    batchUpdate(url, "特殊禁用");
}

function cloneOne() {
    var selectedRow = $("#datagrid").datagrid("getChecked");
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item, index) {
            return item.id;
        });
        var url = "/workshop/copy/";
        $.messager.confirm("提示", "您确定复制吗?", function (r) {
            if (r) {
                updateSalesDetail(url, JSON.stringify(ids), true);
            }
        });
    } else {
        $.messager.alert("提示", "请选择记录", "error");
        return false;
    }

}

//标记批发
function markWholesale() {
    Wholesale("/workshop/markData/",1)
}
//取消批发
function cancelWholesale() {
    Wholesale("/workshop/markData/",0)
}

function Wholesale(url,dataType) {
    var selectedRow = $("#datagrid").datagrid("getChecked");
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item, index) {
            return item.id;
        });
        let message = "";
        if (dataType == 1) {
            message = "标记";
        }else if (dataType == 0) {
            message = "取消";
        }else {
            $.messager.alert("提示", "dataType异常", "error");
            return;
        }

        $.messager.confirm("提示", "您确定" + message + "批发吗?", function (r) {
            if (r) {
                $.ajax({
                    url: config.url + url + dataType,
                    type: "POST",
                    dataType: "json",
                    data: JSON.stringify(ids),
                    contentType: "application/json;charset=UTF-8",
                    xhrFields: {withCredentials: true},
                    beforeSend: function () {
                        $.messager.progress({
                            title: "请稍等",
                            interval: 30,
                            text: "数据标记中..."
                        });
                    },
                    complete: function () {
                        $.messager.progress("close");
                    },
                    success: function (data) {
                        if (data.code == 200) {
                            $.messager.alert("提示", data.msg, "info");
                            searchBy();
                        }else {
                            $.messager.alert("提示", data.msg, "error");
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.progress("close");
                    }
                })
            }
        });
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}

function joinAll() {
    var url = "/workshop/combine";
    batchUpdate(url, "合并");
}

/**
 * 一键修改系数大于1.5
 * @returns {boolean}
 */
function batchUpdatePrice() {
    var data = getFormData(document.getElementById("ff"));
    if (!isMonthType() && !data.week) {
        data.week = window.parent.timeData.weekInYear;
    }

    data.reportType = window.parent.workMode.toUpperCase();
    data.minNum = $("#minNum").textbox('getValue');
    data.maxNum = $("#maxNum").textbox('getValue');
    if($('#categorySelect').combobox("getValue")){
        data.categoryCode =  $('#categorySelect').combobox("getValue");
    }else{
        $.messager.alert("提示","品类不能为空","info");
        return;
    }
    var msg ="您确定执行一键调价吗? ";
    /*data.comboData = $("#comboData").switchbutton("options").checked;
    if(data.comboData){
        msg ="套餐调价应放在非套餐调价之后，是否确定执行套餐数据调价?"
        if(data.categoryCode == "02" || data.categoryCode == "04" || data.categoryCode == "05"
            || data.categoryCode == "07"|| data.categoryCode == "08"
            || data.categoryCode == "09" || data.categoryCode == "10"
            || data.categoryCode == "14" || data.categoryCode == "15"){
        }else{
            $.messager.alert("提示","当前品类品类没有套餐数据","info");
            return;
        }
    }*/
    $.messager.confirm("提示", msg, function (r) {
        if (r) {
            $.ajax({
                url: config.url + "/workshop/avgPriceInit",
                type: "post",
                data: {'year': data.year, 'month': data.month, 'reportType': data.reportType, 'categoryCode': data.categoryCode, 'week': data.week, 'comboData': data.comboData, 'minNum': data.minNum, 'maxNum': data.maxNum},
                dataType: "json",
                xhrFields: {withCredentials: true},
                beforeSend: function () {
                    $.messager.progress({
                        title: "请稍等",
                        interval: 50,
                        text: "数据加载中..."
                    });
                },
                complete: function () {
                    $.messager.progress("close");
                },
                success: function (result) {
                    $.messager.progress("close");
                    if (result.code == "200") {
                        $.messager.alert("提示", result.msg, "info");
                    } else {
                        $.messager.alert("提示", result.msg, "error");
                    }
                },
                error: function (result) {
                    $.messager.alert("提示", result.msg, "error");
                }
            })
        }
    });

}

/**
 * 调整
 * @returns {boolean}
 */
function adjustment() {
    var data = getFormData(document.getElementById("updateff"));
    var updateType = data['updateType'];
    var changeValue = data['changeValue'];
    var number = $("#number").textbox('getValue');
    var selectedRow = $("#datagrid").datagrid("getChecked");
    if (selectedRow != null && selectedRow.length > 0) {
        if (changeValue == "" && (updateType == "T1" || updateType == "T2" || updateType == "T3" ||
            updateType == "T4" || updateType == "T5" || updateType == "T6" || updateType == "T7" ||
            updateType == "T14" || updateType == "T5" || updateType == "T21" || updateType == "T22" ||
            updateType == "T23" || updateType == "T26" || updateType == "T28" || updateType == "T29")) {
            $.messager.alert("提示", "请输入调整值", "error");
            return false;
        }
        if ((number == "" || !number) && updateType == "T29") {
            $.messager.alert("提示", "请输入指定数", "error");
            return false;
        }
        var ids = selectedRow.map(function (item, index) {
            return item.id;
        }).join(",");
        var formdata = getFormData(document.getElementById("ff"));
        var params = {type: updateType, value: changeValue, year: formdata.year, ids: ids, number: number};
        if (isMonthType()) {
            params.month = formdata.month;
        } else {
            params.week = formdata.week;
        }
        params.reportType = window.parent.workMode.toUpperCase();
        var url = "/workshop/update";
        $.messager.confirm("提示", "您确定调整吗?", function (r) {
            if (r) {
                updateSalesDetail2(url, params);
            }
        });
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}

/**
 * 标记
 * @returns {boolean}
 */
function mark() {
    var data = getFormData(document.getElementById("updateff"));
    var updateType = data['markType'];
    var changeValue = data['markValue'];
    var selectedRow = $("#datagrid").datagrid("getChecked");
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item, index) {
            return item.id;
        });
        if (changeValue == "") {
            $.messager.alert("提示", "请输入标记值", "error");
            return false;
        }
        var url = "/sales/detail/" + updateType + "/moveTo/" + changeValue;
        var params = {ids: ids, reportType: window.parent.workMode.toUpperCase()};
        $.messager.confirm("提示", "您确定标记吗?", function (r) {
            if (r) {
                $.when(updateSalesDetail2(url, params, "POST")).done(searchBy());
            }
        });
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}

function markData() {
    var selectedRow = $("#datagrid").datagrid("getChecked");
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item, index) {
            return item.id;
        });
        var url = "/sales/detail/markData";
        var params = {ids: ids};
        $.messager.confirm("提示", "您确定标记吗?", function (r) {
            if (r) {
                $.ajax({
                    url: config.url + url,
                    type: "POST",
                    data: params,
                    traditional: true,
                    dataType: 'JSON',
                    xhrFields: {withCredentials: true},
                    beforeSend: function () {
                        $.messager.progress({
                            title: "请稍等",
                            interval: 30,
                            text: "操作进行中..."
                        });
                    },
                    complete: function () {
                        $.messager.progress("close");
                    },
                    success: function (data) {
                        searchBy();
                    },
                    error: function () {
                        $.messager.progress("close");
                        // if (data) {
                        //     // var res = JSON.parse(data.responseText);
                        //     // $.messager.alert("提示", "操作失败", "error");
                        // }
                    }
                });
            }
        });
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }

}

/**
 * 型号品牌转移
 * @returns {boolean}
 */
function moveTo() {
    var data = getFormData(document.getElementById("updateff"));
    var category = data['categoryCode'];
    var selectedRow = $("#datagrid").datagrid("getChecked");
    var url = "/sales/detail/category/moveTo/" + category;
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item, index) {
            return item.id;
        });
        var params = {reportType: window.parent.workMode.toUpperCase(), ids: ids};
        $.messager.confirm("提示", "您确定转移吗?", function (r) {
            if (r) {
                updateSalesDetail2(url, params, "POST");
            }
        });

    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}

function noneHandle(){
    var selectedRow = $("#datagrid").datagrid("getChecked");
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item, index) {
            return item.id;
        });
        $.messager.confirm("提示", "您确定执行空型号处理吗?", function (r) {
            if (r) {
                var params = JSON.stringify(ids);
                $.ajax({
                    url:config.parseUrl + "/sales-detail/parse-none-data",
                    type:'post',
                    data:params,
                    contentType:"application/json;charset=UTF-8",
                    dataType:'json',
                    headers: {'Authorization': sessionStorage.getItem('Authorization')},
                    xhrFields:{withCredentials:true},
                    beforeSend:function () {
                        $.messager.progress({
                            title:"请稍等",
                            interval:30,
                            text:"数据加载中..."
                        });
                    },
                    complete:function () {
                        $.messager.progress("close");
                    },
                    success:function (data) {
                        $.messager.progress("close");
                        if (data.code == 0) {
                            searchBy();
                            $.messager.alert("提示", data.msg, "info");

                        }else{
                            $.messager.alert("提示", data.msg, "error");
                        }
                    },
                    error:function (XMLHttpRequest,textStatus,errorThrown) {

                    }
                });
            }
        });
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}

/**
 * 标记套餐
 * @returns {boolean}
 */
function markAsMeal() {
    var selectedRow = $("#datagrid").datagrid("getChecked");
    var str = "已选套餐品类：<br/>";
    var comboCategorys = [];
    for (let i = 1; i <= comboMultipleSelectCount; i++) {
        var comboSelect = $("#comboMultipleSelect" + i);
        var comboSelectNum = $("#comboMultipleSelectNum" + i).textbox("getValue");
        if (comboSelect.combotree("getValues") && comboSelectNum) {
            str += "【"+comboSelect.combobox("getText") + "】数量：" + comboSelectNum + "<br/>";
            comboSelect.combotree("getValues").forEach(function (item) {
                comboCategorys.push({categoryCode: item, count: comboSelectNum});
            });
        }

    }
    str += "请确认标记?";
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item, index) {
            return item.id;
        });
        var params = {
            salesDetailIds: ids,
            comboCategoryInfos: comboCategorys,
        };
        var url = "/sales/detail/combo";
        $.messager.confirm("提示", str, function (r) {
            if (r) {
                updateSalesDetailsearchby(url, JSON.stringify(params), true);
            }
        });
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}

/**
 * 取消套餐
 * @returns {boolean}
 */
function cancelMeal() {
    let categoryCode = $('#categorySelect').combobox("getValue");
    var selectedRow = $("#datagrid").datagrid("getChecked");
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item) {
            return item.id;
        });
        var url = "/sales/detail/combo/delete/" + categoryCode;
        $.messager.confirm("提示", "您确定取消套餐吗?", function (r) {
            if (r) {
                updateSalesDetailsearchby(url, JSON.stringify(ids), true, "DELETE");
            }
        });
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}

/**
 * 拆分套餐  原始版本

 function splitMeal() {
    var formdata = getFormData(document.getElementById("ff"));
    var url = "/sales/detail/comboPrice";
    formdata.reportType = window.parent.workMode.toUpperCase();
    $.messager.confirm("提示", "您确定拆分套餐吗?", function (r) {
        if (r) {
            updateSalesDetail2(url, formdata, "POST");
        }
    });
}
 */
/**
 * 拆分套餐 cr
 */
function splitMeal() {
    var formdata = getFormData(document.getElementById("ff"));
    var url = "/sales/detail/splitCombo";
    formdata.reportType = window.parent.workMode.toUpperCase();
    formdata.categoryCode = $('#categorySelect').combobox("getValue");;
    $.messager.confirm("提示", "您确定拆分套餐吗?", function (r) {
        if (r) {
            var method = "POST";
            $.ajax({
                url: config.url + url,
                type: method,
                data: formdata,
                traditional: true,
                dataType: 'JSON',
                xhrFields: {withCredentials: true},
                beforeSend: function () {
                    $.messager.progress({
                        title: "请稍等",
                        interval: 50,
                        text: "操作进行中..."
                    });
                },
                complete: function () {
                    $.messager.progress("close");
                },
                success: function (data) {
                    if(data.code==200){
                        $.messager.alert("提示",data.msg,"info");
                    }else {
                        $.messager.alert("提示",data.msg,"error");
                    }
                },
                error: function () {
                    $.messager.progress("close");
                    if (data) {
                        var res = JSON.parse(data.responseText);
                        $.messager.alert("提示", "操作失败", "error");
                    }
                }
            });

        }
    });
}

/**
 * 大销量拆分
 * @returns {boolean}
 */
function largeSalesSplit() {
    var selectedRow = $("#datagrid").datagrid("getChecked");
    var formdata = getFormData(document.getElementById("updateff"));
    var num = formdata.num;
    if (!num || isNaN(num)) {
        $.messager.alert("提示", "请输入拆分条数", "error");
        return false;
    }
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item) {
            return item.id;
        }).join(",");
        var url = "/workshop/split";
        var params = {num: num, ids: ids};
        params.year = getFormData(document.getElementById("ff")).year;
        params.reportType = window.parent.workMode.toUpperCase();
        if (isMonthType()) {
            params.month = getFormData(document.getElementById("ff")).month;
        } else {
            params.week = getFormData(document.getElementById("ff")).week;
        }
        $.messager.confirm("提示", "您确定拆分大销量吗?", function (r) {
            if (r) {
                updateSalesDetail2(url, params, "POST");
            }
        });

    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}

/**
 * 设置空型号
 * @returns {boolean}
 */
function setEmptyModel() {
    var formdata = getFormData(document.getElementById("updateff"));
    var selectedRow = $("#datagrid").datagrid("getChecked");
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item) {
            return item.id;
        });
        var values = [];
        for (var key in formdata) {
            if (!isNaN(key)) {
                var prop = key;
                values.push({code: key, value: formdata[key]});
            }
        }
        var url = "/workshop/mark";
        var params = {ids: ids, values: values};
        $.messager.confirm("提示", "您确定设置空型号吗?", function (r) {
            if (r) {
                updateSalesDetailsearchby(url, JSON.stringify(params), true);
            }
        });
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}

/**
 * 取消空型号
 * @returns {boolean}
 */
function cancelEmptyModel() {
    var selectedRow = $("#datagrid").datagrid("getChecked");
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item, index) {
            return item.id;
        });
        var url = "/workshop/mark", method = "DELETE", params = JSON.stringify(ids);
        $.messager.confirm("提示", "您确定取消空型号吗?", function (r) {
            if (r) {
                updateSalesDetailsearchby(url, params, true, method);
            }
        });
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}

/**
 *
 * @returns {boolean}
 */
function handleEmptyModel() {
    var selectedRow = $("#datagrid").datagrid("getChecked");
    var formdata = getFormData(document.getElementById("updateff"));
    var pct = formdata.pct, year = formdata.year, periods = formdata.periods;
    if (!pct || !year || !periods) {
        $.messager.alert("提示", "请输入参数", "warn");
        return false;
    }
    if (isNaN(pct) || isNaN(year)) {
        $.messager.alert("提示", "请输入正确的参数", "warn");
        return false;
    }
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item, index) {
            return item.id;
        }).join(",");
        var url = "/workshop/handleMarked", method = "POST", params = {year: year, periods: periods, pct: pct + "%", ids: ids};
        var thisPeriod = $("#thisPeriod").combobox("getValue");
        var top = $("#top").val();
        params.reportType = window.parent.workMode.toUpperCase();
        params.thisPeriod = thisPeriod;
        params.top = top;
        $.messager.confirm("提示", "您确定处理空型号吗?", function (r) {
            if (r) {
                updateSalesDetaildd(url, params, method);
            }
        })
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}

/**
 * 直接修改品牌码型号码
 * @param ele
 * @returns {boolean}
 */
function updateCurrentRow(ele) {
    var $this = ele;
    var id = $this.id;
    var name = $this.name;
    var value = $this.value;
    var _value = $this.getAttribute("_value");
    if (value == _value) return false;
    var url = "/sales/detail/" + name + "/moveTo/" + value;
    if (/price/i.test(name)) {
        url = "/sales/detail/" + name + "/change/" + value;
    }
    updateSalesDetail2(url, {ids: [id], reportType: window.parent.workMode.toUpperCase()}, "POST");
    $this.setAttribute("_value", value);
    return status;
}

/**
 * 批量修改
 * @param originalModel
 * @param modelCode
 * @returns {boolean}
 */
function batchReplace(salesDetailId, modelCode) {
    var formdata = getFormData(document.getElementById("ff"));
    var params = {
        year: formdata.year,
        salesDetailId: salesDetailId,
        modelCode: modelCode,
        reportType: window.parent.workMode.toUpperCase()
    };
    if (isMonthType()) {
        params.month = formdata.month;
    } else {
        params.week = formdata.week;
    }
    var url = "/workshop/update2";
    //update
    console.log("批量修改=======================")
    updateSalesDetail3(url, params);
}

function valueSets(obj) {
    var res = [];
    for (var i in obj) {
        if("seriesCode" !=i){
            res.push(obj[i]);
        }
    }
    return res;
}

function selectRowByModelName(modelName) {
    $("#originalModel").textbox("setValue", modelName);
    $.when(searchBy()).done(function () {
        $("#datagrid").datagrid("checkAll");
    });
}
//添加特殊追加禁用库
function addDisableMatch() {
    var selectedRow = $("#datagrid").datagrid("getChecked");
    var special = $("#special").combobox('getValue');
    var remark = $("#remark").textbox('getValue')
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item, index) {
            return item.id;
        });
        var url = "/v2/suspectedHistoryMatchData/addDisableMatch", method = "POST",params = {
            salesDetailIds: ids,
            special: special,
            remark:remark,
        };;
        $.messager.confirm("提示", "您确定追加禁用库吗?", function (r) {
            if (r) {
                $("#addDisable").dialog('close');
                updateSalesDetaildd(url, params, "POST");
            }
        })
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}

function notAppendOtherNames(id) {
    var ids=[];
    if (id) {
        ids[0] = id;
    } else {
        var selectedRow = $("#datagrid").datagrid("getChecked");
        if (selectedRow != null && selectedRow.length > 0) {
            ids = selectedRow.map(function (item, index) {
                return item.id;
            });
        } else {
            $.messager.alert("提示", "请选择相关记录", "error");
            return false;
        }
    }
    var params = JSON.stringify(ids);
    $.messager.confirm("提示", "您确定不追加别名库吗?", function (r) {
        if (r) {
            $.ajax({
                url:config.url + "/workshop/notAppendOtherNameById",
                type:'post',
                data:params,
                dataType:'json',
                async: false,
                contentType: "application/json;charset=UTF-8",
                xhrFields:{withCredentials:true},
                beforeSend:function () {
                    $.messager.progress({
                        title:"请稍等",
                        interval:30,
                        text:"数据加载中..."
                    });
                },
                complete:function () {
                    $.messager.progress("close");
                },
                success:function (data) {
                    if(data.code == 200){
                        $('#addModelParticiple').dialog('close');
                        $.messager.show({
                            title: '提示',
                            msg: data.msg,
                            timeout: 1000,
                            showType: 'slide'
                        });
                        searchBy();
                    }else {
                        $.messager.alert("错误",data.msg,"error");
                    }
                },
                error:function (XMLHttpRequest,textStatus,errorThrown) {

                }
            });
        }
    })
}

function continuousAppendOtherNames() {
    var data = {};
    let formData = getFormData(document.getElementById("ff"));
    if($('#categorySelect').combobox("getValue")){
        data.categoryCode =  $('#categorySelect').combobox("getValue");
    }else{
        $.messager.alert("提示","品类不能为空","info");
        return;
    }
    data.year =formData.year;
    data.week = formData.week;
    data.month = formData.month;
    data.reportType=window.parent.workMode.toUpperCase();
    $.ajax({
        url: config.url + "/workshop/getAppedOtherNameDataOne",
        type: "get",
        data: data,
        xhrFields: {withCredentials: true},
        beforeSend: function () {
            $.messager.progress({
                title: "请稍等",
                interval: 30,
                text: "操作进行中..."
            });
        },
        success: function (data) {
            $.messager.progress("close");
            if (data.code == 200) {
                if(data.msg){
                    addparticiple(data.msg);
                }else {
                    $.messager.alert("提示", "当前品类没有需要加别名的数据", "info");
                }
            }else{
                $.messager.alert("提示", data.msg, "error");
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $.messager.progress("close");
        }
    })
}

/*
 用于查询时显示进度条
*/
function updateSalesDetailsearchby(url, data, refresh, methodtype) {
    var method = methodtype || "POST";
    $.ajax({
        url: config.url + url,
        type: method,
        dataType: "json",
        data: data,
        contentType: "application/json;charset=UTF-8",
        xhrFields: {withCredentials: true},
        beforeSend: function () {
            $.messager.progress({
                title: "请稍等",
                interval: 50,
                text: "操作进行中..."
            });
        },
        success: function (data) {
            if (data.code == 515) {
                $.messager.alert("提示",data.msg,"error");
            }
            if (data && refresh) {
                searchBy();
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $.messager.progress("close");
        }
    })
}

function searchBymodelf() {
    var params = {};
    var formdata = getFormData(document.getElementById("filling"));
    // console.log(formdata);
    if($('#categorySelect').combobox("getValue")){
        params.categoryCode =  $('#categorySelect').combobox("getValue");
    }else{
        $.messager.alert("提示","品类不能为空","info");
        return;
    }
    params.brandCode = formdata.brandCode;
    params.name = $('#modelNameNew').textbox('getValue');
    params.model = true;
    // console.log(params);
    $.ajax({
        url: config.url + "/workshop/modelCheck",
        type: "post",
        data: params,
        xhrFields: {withCredentials: true},
        success: function (data) {
            if (data == "") {
                $.messager.alert("提示", "该型号不存在，可以添加", "info")
            } else {
                $.messager.alert("提示", data, "error");
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {

        }
    });
}

/**
 * 导入空型号数据
 * @returns
 */
function ImportNoneData() {
    $("#upmall").window("open");
}

/**
 * 自动合并
 */
function autoMerge() {
    var data = getFormData(document.getElementById("ff"));
    data.reportType = window.parent.workMode.toUpperCase();
    if($('#categorySelect').combobox("getValue")){
        data.categoryCode =  $('#categorySelect').combobox("getValue");
    }else{
        $.messager.alert("提示","品类不能为空","info");
        return;
    }
    $.messager.confirm("提示", "您确定执行自动合并吗?", function (r) {
        if (r) {
            $.ajax({
                url: config.url +"/workshop/autoMerge",
                type: "POST",
                data: data,
                dataType: "json",
                xhrFields: {withCredentials: true},
                beforeSend: function () {
                    $.messager.progress({
                        title: "请稍等",
                        interval: 30,
                        text: "操作进行中..."
                    });
                },
                success: function (data) {
                    if (data.code == 200) {
                        $.messager.alert("提示",data.msg,"info");
                    }else {
                        $.messager.alert("提示",data.msg,"error");
                    }
                    searchBy();
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress("close");
                }
            })
        }
    })
}
function participleSelect(selectId,data){
    var dtd = $.Deferred();
    if(data){
        var strLength = 0;
        var strIndex = -1;
        var participleData = [];
        for(var i=0;i<data.length;i++){
            let str = data[i];
            participleData[i] = {"name":str, "text": str};
            if (str.length > strLength) {
                strIndex = i;
                strLength = str.length;
            }
        }
        if (strIndex>0) {
            let index0 = participleData[0];
            participleData[0] = participleData[strIndex];
            participleData[strIndex] = index0;
        }

        $("#"+selectId).combobox({
            "textField":"name",
            "valueField":"text",
            "panelHeight":150,
            // "prompt":"--请选择--",
            "data":participleData,
            onChange:function(newValue,oldValue){
                $('#otherName').textbox('setValue', newValue);
            }
        });
        $("#" + selectId).combobox("setValue", participleData[0]);
    }
    return dtd.promise();
}
function addOtherNames() {
    var dtd = $.Deferred();
    var parm = getFormData(document.getElementById("formParticiple"));
    parm.reportType=window.parent.workMode.toUpperCase();
    parm.year = pageYear;
    parm.week = pageWeek;
    parm.month = pageMonth;
    parm.categoryCode = pageCategory;
    parm.tips = $("#participle").combobox("getValue");
    parm.otherName = $("#otherName").textbox("getValue");
    if (!parm.tips) {
        $.messager.alert("提示","请选择分词","error");
        return;
    }

    $.ajax({
        url:config.url + "/workshop/addModelOtherName",
        type:'post',
        data:parm,
        dataType:'json',
        async: false,
        xhrFields:{withCredentials:true},
        beforeSend:function () {
            $.messager.progress({
                title:"请稍等",
                interval:30,
                text:"数据加载中..."
            });
        },
        complete:function () {
            $.messager.progress("close");
        },
        success:function (data) {
            if(data.code == 200){
                $('#addModelParticiple').dialog('close');
                $.messager.show({
                    title: '提示',
                    msg: data.msg,
                    timeout: 1000,
                    showType: 'slide'
                });
                searchBy();
            }else if(data.code == 201){
                $.messager.confirm("提示", data.msg+",是否继续执行修改数据操作？", function (r) {
                    if (r) {
                        $.ajax({
                            url: config.url +"/workshop/notAppendOtherNameByModelCode",
                            type: "POST",
                            data: parm,
                            dataType: "json",
                            async: false,
                            xhrFields: {withCredentials: true},
                            beforeSend: function () {
                                $.messager.progress({
                                    title: "请稍等",
                                    interval: 30,
                                    text: "操作进行中..."
                                });
                            },
                            success: function (data) {
                                if (data.code == 200) {
                                    $('#addModelParticiple').dialog('close');
                                    $.messager.show({
                                        title: '提示',
                                        msg: data.msg,
                                        timeout: 1000,
                                        showType: 'slide'
                                    });
                                    searchBy();
                                }else {
                                    $.messager.alert("提示",data.msg,"error");
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                $.messager.progress("close");
                            }
                        })
                    }
                })
            }else {
                $.messager.alert("错误",data.msg,"error");
            }
        },
        error:function (XMLHttpRequest,textStatus,errorThrown) {

        }
    });
    return dtd.promise();
}    function aa(){
    $.ajax({
        url:config.url + "/cron/cache/data/refresh",
        type:'get',
        xhrFields:{withCredentials:true},
        beforeSend:function () {
            $.messager.progress({
                title:"请稍等",
                interval:50,
                text:"数据加载中..."
            });
        },
        complete:function () {
            $.messager.progress("close");
        },
        success:function (data) {

        },
        error:function (XMLHttpRequest,textStatus,errorThrown) {

        }
    });
    var categoryCode=$("#categorySelectAdd").combobox('getValue');
    var brandCode=$("#brandSelectAdd").combobox('getValue');
    initBrandSelectC("brandSelectAdd",null,null,categoryCode,brandCode);
}
function Identify() {
    if(!$('#categorySelect').combobox("getValue")){
        $.messager.alert("提示","品类不能为空","info");
        return;
    };
    var ids=[];
    var selectedRow = $("#datagrid").datagrid("getChecked");
    if (selectedRow != null && selectedRow.length > 0) {
        ids = selectedRow.map(function (item, index) {
            return item.id;
        });
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
    var params = JSON.stringify(ids);
    $.messager.confirm("提示", "您确定要执行重新识别吗？", function (r) {
        if (r) {
            $.ajax({
                url:config.parseUrl + "/sales-detail/repeat-identify",
                type:'post',
                data:params,
                contentType:"application/json;charset=UTF-8",
                dataType:'json',
                headers: {'Authorization': sessionStorage.getItem('Authorization')},
                xhrFields:{withCredentials:true},
                beforeSend:function () {
                    $.messager.progress({
                        title:"请稍等",
                        interval:30,
                        text:"数据加载中..."
                    });
                },
                complete:function () {
                    $.messager.progress("close");
                },
                success:function (data) {
                    $.messager.progress("close");
                    if (data.code == 0) {
                        searchBy();
                        $.messager.alert("提示", data.msg, "info");

                    }else{
                        $.messager.alert("提示", data.msg, "error");
                    }
                },
                error:function (XMLHttpRequest,textStatus,errorThrown) {

                }
            });
        }
    });
    return dtd.promise();
}

function imgNext(){
    currentIndex++;
    $('#addModelNone').dialog('close');
    let row = $('#datagrid').datagrid('getRows')[currentIndex];
    window.currentRecord = row;
    if (!row || !row.modelCode) {
        addModel(row);
        $("#brandName").textbox("setValue",row.brandName);
        let modelName = row.originalModel;
        var modelreg = modelName.replace(/[\u4e00-\u9fa5]/g,"");
        modelreg = modelreg.replace(/\ /g,"");
        searchByModel(modelreg);
    }
}

/**
 * 数据标记
 * @returns {boolean}
 */
function dataMark(){
    var selectedRow = $("#datagrid").datagrid("getChecked");
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item, index) {
            return item.id;
        });
        var url = "/workshop/dataMark";
        var params = JSON.stringify(ids);
        $.messager.confirm("提示", "您确定标记数据吗?", function (r) {
            if (r) {
                $.ajax({
                    url: config.url + url,
                    type: "POST",
                    data: params,
                    traditional: true,
                    contentType:"application/json;charset=UTF-8",
                    dataType: 'JSON',
                    xhrFields: {withCredentials: true},
                    beforeSend: function () {
                        $.messager.progress({
                            title: "请稍等",
                            interval: 30,
                            text: "操作进行中..."
                        });
                    },
                    complete: function () {
                        $.messager.progress("close");
                    },
                    success: function (result) {
                        if (result.code == "200") {
                            $.messager.alert("提示", result.msg, "info");
                            searchBy();
                        } else {
                            $.messager.alert("提示", result.msg, "error");
                        }
                    },
                    error: function () {
                        $.messager.progress("close");
                    }
                });
            }
        });
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}

function cancelMark(){
    var selectedRow = $("#datagrid").datagrid("getChecked");
    if (selectedRow != null && selectedRow.length > 0) {
        var ids = selectedRow.map(function (item, index) {
            return item.id;
        });
        var url = "/workshop/cancelMark";
        var params = JSON.stringify(ids);
        $.messager.confirm("提示", "您确定取消标记吗?", function (r) {
            if (r) {
                $.ajax({
                    url: config.url + url,
                    type: "POST",
                    data: params,
                    traditional: true,
                    contentType:"application/json;charset=UTF-8",
                    dataType: 'JSON',
                    xhrFields: {withCredentials: true},
                    beforeSend: function () {
                        $.messager.progress({
                            title: "请稍等",
                            interval: 30,
                            text: "操作进行中..."
                        });
                    },
                    complete: function () {
                        $.messager.progress("close");
                    },
                    success: function (result) {
                        if (result.code == "200") {
                            $.messager.alert("提示", result.msg, "info");
                            searchBy();
                        } else {
                            $.messager.alert("提示", result.msg, "error");
                        }
                    },
                    error: function () {
                        $.messager.progress("close");
                    }
                });
            }
        });
    } else {
        $.messager.alert("提示", "请选择相关记录", "error");
        return false;
    }
}
/**
 * 均价禁用
 */
function avgPriceDisable() {
    var data = getFormData(document.getElementById("ff"));
    if (!isMonthType() && !data.week) {
        data.week = window.parent.timeData.weekInYear;
    }

    data.reportType = window.parent.workMode.toUpperCase();
    if ($('#categorySelect').combobox("getValue")) {
        data.categoryCode = $('#categorySelect').combobox("getValue");
    } else {
        $.messager.alert("提示", "品类不能为空", "info");
        return;
    }
    var msg = "您确定执行均价禁用吗? ";
    $.messager.confirm("提示", msg, function (r) {
        if (r) {
            $.ajax({
                url: config.url + "/workshop/disableOfD20",
                type: "post",
                data: data,
                xhrFields: {withCredentials: true},
                beforeSend: function () {
                    $.messager.progress({
                        title: "请稍等",
                        interval: 50,
                        text: "操作进行中..."
                    });
                },
                complete: function () {
                    $.messager.progress("close");
                },
                success: function (result) {
                    $.messager.progress("close");
                    if (result.code == "200") {
                        $.messager.alert("提示", result.msg, "info");
                        searchBy();
                    } else {
                        $.messager.alert("提示", result.msg, "error");
                    }
                },
                error: function (result) {
                    $.messager.alert("提示", result.msg, "error");
                }
            });
        }
    });
}

/**
 * 标记转移
 */
function markTransfer(){
    var data = getFormData(document.getElementById("ff"));
    if (!isMonthType() && !data.week) {
        data.week = window.parent.timeData.weekInYear;
    }

    data.reportType = window.parent.workMode.toUpperCase();
    if ($('#categorySelect').combobox("getValue")) {
        data.categoryCode = $('#categorySelect').combobox("getValue");
    } else {
        $.messager.alert("提示", "品类不能为空", "info");
        return;
    }
    var msg = "您确定执行标记转移吗? ";
    $.messager.confirm("提示", msg, function (r) {
        if (r) {
            $.ajax({
                url: config.url + "/workshop/v2/markTransfer",
                type: "post",
                data: data,
                xhrFields: {withCredentials: true},
                beforeSend: function () {
                    $.messager.progress({
                        title: "请稍等",
                        interval: 50,
                        text: "操作进行中..."
                    });
                },
                complete: function () {
                    $.messager.progress("close");
                },
                success: function (result) {
                    $.messager.progress("close");
                    if (result.code == "200") {
                        $.messager.alert("提示", result.msg, "info");
                        searchBy();
                    } else {
                        $.messager.alert("提示", result.msg, "error");
                    }
                },
                error: function (result) {
                    $.messager.alert("提示", result.msg, "error");
                }
            });
        }
    });

}

/**
 * 拼抖快专用一键处理
 */
function pdkBatchHandle() {
    var data = getFormData(document.getElementById("ff"));
    if (!isMonthType() && !data.week) {
        data.week = window.parent.timeData.weekInYear;
    }

    data.reportType = window.parent.workMode.toUpperCase();
    if ($('#categorySelect').combobox("getValue")) {
        data.categoryCode = $('#categorySelect').combobox("getValue");
    } else {
        $.messager.alert("提示", "品类不能为空", "info");
        return;
    }
    var msg = "您确定执行一键处理吗? ";
    $.messager.confirm("提示", msg, function (r) {
        if (r) {
            $.ajax({
                url: config.url + "/workshop/batchHandle",
                type: "post",
                data: data,
                xhrFields: {withCredentials: true},
                beforeSend: function () {
                    $.messager.progress({
                        title: "请稍等",
                        interval: 50,
                        text: "操作进行中..."
                    });
                },
                complete: function () {
                    $.messager.progress("close");
                },
                success: function (result) {
                    $.messager.progress("close");
                    if (result.code == "200") {
                        $.messager.alert("提示", result.msg, "info");
                        searchBy();
                    } else {
                        $.messager.alert("提示", result.msg, "error");
                    }
                },
                error: function (result) {
                    $.messager.alert("提示", result.msg, "error");
                }
            });
        }
    });

}